package boyan.douban;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import boyan.model.BookInfo;

public class Export {
	
	public static void export(List<BookInfo> bookinfos){
		OutputStream fos = null;
		try {
			fos = new FileOutputStream("D://craw.xls");

			List<String> head = new ArrayList<String>();
			head.add("序号");
			head.add("书名");
			head.add("评分");
			head.add("评价人数");
			head.add("作者");
			head.add("出版社");
			head.add("出版日期");
			head.add("价格");
			
			List<List<String>> body = new ArrayList<List<String>>();
			int i= 0;
			for (BookInfo bookinfo : bookinfos) {
				List<String> b1 = new ArrayList<String>();
				i++;
				b1.add(Integer.toString(i));
				b1.add(bookinfo.getBookName() );
				b1.add(bookinfo.getRating() );
				b1.add(bookinfo.getRatingNums() );
				b1.add(bookinfo.getAuthor() );
				b1.add(bookinfo.getPress() );
				b1.add(bookinfo.getDatePress() );
				b1.add(bookinfo.getMoney() );
				body.add(b1);
			}
			
			ExcelUtils.exportExcel(head, body, fos);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
}
